﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace HMEngine.HMObjects {
    public class HMQuad : HMObject {
        private readonly string myAsset;

        public VertexPositionColorTexture[] Vertices { get; set; }
        public Color Color { get; set; }
        public Texture2D Texture { get; set; }
        public short[] Indexes { get; set; }

        public HMQuad(string textureAsset, Color color) {
            myAsset = textureAsset;
            Color = color;
            Scaling = new Vector3(1);
        }

        public override void LoadContent(GraphicsDevice myDevice, ContentManager myLoader) {
            Texture = myLoader.Load<Texture2D>(myAsset);

            Vertices = new[] {
                new VertexPositionColorTexture(new Vector3(-0.5f, 0.5f, 0), Color, new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(0.5f, 0.5f, 0), Color, new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, 0), Color, new Vector2(0, 1)),
                new VertexPositionColorTexture(new Vector3(0.5f, -0.5f, 0), Color, new Vector2(1, 1))
            };

            Indexes = new short[] { 0, 1, 2, 1, 3, 2 };
        }

        public override void Render(GraphicsDevice myDevice) {
            myDevice.Textures[0] = Texture;
            myDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, Vertices, 0, 4, Indexes, 0, 2);
        }

        public override void UnloadContent() { }
    }
}